﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace AGameOfThrones.ui
{
    public class manager : System.Windows.Threading.DispatcherObject
    {
        public Dictionary<String, UserControl> Pieces { get; set; }
        public Dictionary<String, Panel> Panels { get; set; }


        public manager()
        {
            Pieces = new Dictionary<String, UserControl>();
            Panels = new Dictionary<String, Panel>();
        }
        
        public void MovePiece(MovePieceEvent e)
        {

            if(Pieces.ContainsKey(e.Message.PieceName))
            {
                UserControl piece = Pieces[e.Message.PieceName];
                if (Panels.ContainsKey(e.Message.NewPosition.Panel))
                {
                    Panel destination = Panels[e.Message.NewPosition.Panel];
                    if (Panels.ContainsKey(e.Message.OldPosition.Panel))
                    {
                        Panel origin = Panels[e.Message.OldPosition.Panel];
                        origin.Children.Remove(piece);
                    }

                    piece.Margin = new System.Windows.Thickness(e.Message.NewPosition.X, e.Message.NewPosition.Y, 0, 0);
                    destination.Children.Add(piece);
                }                                  
            }
        }

        public delegate void OnMovePieceDelegate(MovePieceEvent e);

        public class MovePieceEvent : EventArgs
        {   
            public messages.process_movepiece Message { get; set; }
            public MovePieceEvent(messages.process_movepiece in_message)
            {
                Message = in_message;
            }
        };



    }
}
